Home > Java Programming > Flow Control > Questions and Answers
01. |
class A{ Public static void main(String args[]){ System.out.println(i); int I; } } | |||||||||||
|
02. |
class A{ Public static void main(String args[]){ Int i=10; System.out.println(i); int j=20; System.out.println(j); } } | |||||||||||
|
03. |
class A{ Public static void main(String args[]){ Int i; System.out.println(“helloâ€); } } | |||||||||||
|
04. |
Find the missing snippet in the below code : 1. public class Test { 2. public static void main(String [ ] args) { 3. 4. switch(a) { 5. default: 6. System.out.println("You choose correct option"); 7. } } } Which given below snippet is best for inserting at line number 3 to compile the above code successfully :- | |||||||||||
|
05. |
What is the Output of below code after compilation : 1 .public class Question3{ 2 .public static void main(String[] args) { 3 .try { 4 .int a= (int)(Math.random()*5); 5 .if(a<=2.5) 6 .System.out.println("a="+a); 7 .else 8 .throw new Exception("a>2.5"); 9. } catch (Exception e){ 10. System.err.println(e.getMessage() ); 11. System.err.println("Value of a="+a); 12. } } } Find the output of the following code : | |||||||||||
|
06. |
Find the Output Of the following Code: 1. import java.io.*; 2. public class Example4 { 3. public static void main(String[] args) { 4. Example4 e4 = new Example4(); 5. try{ 6. e4.check();} 7. catch(IOException e){}} 8. void check() throws IOException{ 9. System.out.println("Inside check() method of Class "); 10. throw new IOException();}} 11. class Subexample4 extends Example4 { 12. void check() { 13. System.out.println("Inside check() Method of Subclass"); 14. }} What will be the output of the following code snippet : | |||||||||||
|
07. |
What should be at line number 3 to get the total sum of array "sum" ? public int totalsum( int[] sum ){ int a, b= 0 ; //which 'for' loop should be here(line :3) { b += sum[ a++ ] ; } return b ; } Which 'for' loop should be at line number 3 to calculate total sum of the array "sum" : | |||||||||||
|
08. |
Which are correct input-output options : public class Example6{ public static void main(String args[]) { public int check(char a) { if (a <= 'N') { if (a == 'E') return 2; return 1; } else if (a == 'S') return 3; else if (a == 'W') return 4; return 0; } } } Options are : | |||||||||||
|
09. |
Which one is correct option : 1. public class Example7 { 2. public static void main(String args[]) { 3 . Example7 e7 = new Example7(); 4. int b = ? ; 5. e7.Movie(b); 6. } 7. public void Movie(int q) { 8. switch (q) { 9. case 1: 10. System.out.print("me "); 11. case 2: 12 .System.out.print("myself "); 13 .break; 14. case 3: 15. System.out.print("Irene "); 16. default: 17. System.out.print("Movie"); 18. }}} Which input-output option is correct : | |||||||||||
|
10. |
What is the output of the following code: public class Example10 { public static void main(String[] argv) { SubExample2 se = new SubExample2(); se.showTitle(); } } class SubExample1{ String Name; public SubExample1(String n) { Name = n; } public void showName() { System.out.println("Name is " + Name); } } class SubExample2 extends SubExample1 { public void setName(String nn) { Name = nn; } } What is the output of the above given code : | |||||||||||
|